<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>

//js必须放在你所操作的dom树之前
	<script>
		window.onload=function(){
			var oDiv=document.getElementById("div1");
			oDiv.onclick=function(){
				this.style.background="green";
				
			}
		}

	</script>
</head>

<body>
	<div id="div1"></div>
</body>
</html>
